package pl.edu.agh.gt.real;

import java.util.Date;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;

import pl.edu.agh.gt.data.Rate;
import pl.edu.agh.gt.gui.ChartDisplay;
import pl.edu.agh.gt.stock.CounterTrader;
import pl.edu.agh.gt.stock.Stock;
import pl.edu.agh.gt.stock.Trader;
import pl.edu.agh.gt.strategy.GreedyStrategy;
import pl.edu.agh.gt.strategy.Strategy;

public class CheckStrategyMain {
	
	private final static Logger log = Logger.getLogger(CheckStrategyMain.class);

	public static void main(String[] args) {
		
		try {
			Logger.getLogger("pl.edu.agh.gt.strategy").setLevel(Level.DEBUG);
			Logger.getLogger("pl.edu.agh.gt.stock").setLevel(Level.DEBUG);

			@SuppressWarnings("deprecation")
			Date start = new Date(2005 - 1900, 3, 15);

			@SuppressWarnings("deprecation")
			Date end = new Date(2005 - 1900, 8, 15);

			// Stock stock = new
			// Stock("C:\\Users\\kpajak\\Documents\\Studia\\MAGISTERA\\materialy_mgr\\EURUSD_hour.csv",start,end);
			Stock stock = new Stock("src/main/resources/EURUSD_hour.csv", start, end);

			Strategy strategy1 = new GreedyStrategy(871.9621 ,101.33307 ,133.48843 ,0.2885723 ,-1189.2072);
			
			Trader greedy = new Trader("GREEDY", stock, strategy1);
			greedy.setLogTrading(true);
			
			Strategy strategy2 = new GreedyStrategy(871.9621 ,101.33307 ,133.48843 ,0.2885723 ,-1189.2072);
			CounterTrader greedyCnt = new CounterTrader("GREEDY_CNT", stock, strategy2);
			greedyCnt.setLogTrading(true);
			
			stock.addTrader(greedy);
			stock.addTrader(greedyCnt);

			stock.runStock();
			
			Rate lastRate = stock.getRatesHistory().getLastRate();
			
			log.info("Trader " + greedy.name + " total:" + greedy.evaluate(lastRate)
					+ ", maxInvested: " + greedy.maxInvested + ", buys: " + greedy.buyActions + ", close: " + greedy.closeActions
					+ ", sell: " + greedy.sellActions);
			
			log.info("Trader " + greedyCnt.name + " total:" + greedyCnt.evaluate(lastRate)
					+ ", maxInvested: " + greedyCnt.maxInvested + ", buys: " + greedyCnt.buyActions + ", close: " + greedyCnt.closeActions
					+ ", sell: " + greedyCnt.sellActions);
			

			ChartDisplay.tradingChart("Greedy strategy in normal and counter trader (diff scales!)", stock.getRatesHistory(),
					greedy.getTradingHistory(), greedyCnt.getTradingHistory());
			

		} catch (Exception e) {
			log.error("Stock exception", e);
		}
		
	}
}
